package org.jetlinks.demo.protocol.siterwell.tcp.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

@Getter
@AllArgsConstructor
public enum DirectiveType {
    EMPTY("空指令", ""),
    LOGIN("登录", "01"),
    BREAK_OFF("断开", "03"),
    ALARM("报警", "04"),
    LOW_POWER("低电", "05"),
    NORMAL("正常", "06"),
    MUTE("静音", "07"),
    FAULT("故障", "08"),
    OPEN_D2S("开启", "0a"),
    CLOSE_D2S("关闭", "0b"),
    POWER_FAILURE("断电", "0d"),
    POWER_ON("上电", "0e"),
    RESTORE_LINK("恢复链接", "13"),
    VOLTAGE_NORMAL("电压正常", "15"),
    READ_SENSOR("读取传感器", "20"),
    WRITE_SENSOR("写取传感器", "21"),
    DEPLOY_FOR_DEFENCE("布防", "22"),
    DEPLOY_REMOVE("撤防", "23"),
    TEST_ALARM("测试报警", "24"),
    TILT_ALARM("倾斜报警", "25"),
    ADD_DEVICE("添加设备", "26"),
    REMOVE_DEVICE("删除设备", "27"),
    OPEN_S2D("(下行)开启", "6a"),
    CLOSE_S2D("(下行)关闭", "6b");

    private String desc;
    private String code;

    public static Optional<DirectiveType> of(String directive) {
        DirectiveType[] directives = values();
        String lowerCaseDirective = directive.toLowerCase();
        int len = directives.length;
        for (int i = 0; i < len; i++) {
            DirectiveType curDirective = directives[i];
            if (curDirective.getCode().equals(lowerCaseDirective)) {
                return Optional.of(curDirective);
            }
        }
        return Optional.empty();
    }

}
